package com.cmccgz.udacs_landlord_webapp.main.accreditmanager;

import com.cmccgz.udacs_landlord_webapp.base.ApiService;
import com.cmccgz.udacs_landlord_webapp.bean.Person;
import com.cmccgz.udacs_landlord_webapp.bean.ResultBean;
import com.cmccgz.udacs_landlord_webapp.data.HouseManagerRepository;

import java.util.List;

import rx.Subscriber;

/**
 * @author: June
 * @Descripion:
 * @date 2017/10/27 09:11
 */

public class PersonListPresenter implements PersonListContract.PersonListPresenter {

    private final PersonListContract.PersonListView mListView;
    private HouseManagerRepository mRepository;
    private String searchType;

    public PersonListPresenter(PersonListContract.PersonListView mListView) {
        this.mListView = mListView;
        this.mListView.setPresenter(this);
    }


    @Override
    public void start() {
        mListView.showLoading();
    }

    @Override
    public void getData(String mobile, String houseId) {
        ApiService.getRenterList(mobile,houseId).subscribe(new Subscriber<ResultBean<List<Person>>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                mListView.refreshDataFailed("获取人员数据失败！");
            }

            @Override
            public void onNext(ResultBean<List<Person>> personResultBean) {
                if ("0".equals(personResultBean.rsmsg.rscode)) {
                    mListView.refreshDataSuccess(personResultBean.resp);
                }else{
                    mListView.refreshDataFailed(personResultBean.rsmsg.rsdesc);
                }
            }
        });
    }
}
